<template>
  <section class="switch">
    <el-switch v-model="value" :disabled="disabled" :active-text="activetext" :inactive-text="inactivetext" @change="handleChange" />
  </section>
</template>
<script>
import mixins from './../mixins'
export default {
  name: 'VSwitch',
  mixins: [mixins],
  props: {
    option: {
      type: Object,
      default: {
        value: false,
        disabled: false,
        required: false,
        activetext: '是',
        inactivetext: '否'
      }
    }
  },
  computed: {
    disabled() {
      return this.option.disabled
    },
    required() {
      return this.option.required
    },
    activetext() {
      return this.option.activetext || ''
    },
    inactivetext() {
      return this.option.inactivetext || ''
    }
  },
  created() {
    if (this.option.override !== undefined) {
      this.option.override(this, this.value)
    }
  },
  methods: {
    getValue() {
      return this.value
    },

    setValue(v) {
      this.$set(this, 'value', v)
      if (this.option.override !== undefined) {
        this.option.override(this, this.value)
      }
    },

    check() {
      return true
    },

    handleChange(e) {
      if (this.option.override !== undefined) {
        this.option.override(this, e)
      }
      this.dispatch_event('filed-value-change', e)
    }
  }
}
</script>
